package dao

import (
	"blog/models"
	"log"
)

func GetUserNameById(UserId int) (string, error) {
	row := DB.QueryRow("select user_name from blog_user where uid = ?", UserId)
	if row.Err() != nil {
		log.Println("GetUserNameById查询失败", row.Err())
		return "", row.Err()
	}
	var userName string
	err := row.Scan(&userName)
	if err != nil {
		log.Println("GetUserNameById取值失败", err)
		return "", err
	}
	return userName, err
}
func GetUser(username, passwd string) (user models.User, err error) {
	row := DB.QueryRow("select * from blog_user where user_name = ? And passwd = ? limit 1", username, passwd)
	if row.Err() != nil {
		log.Println("GetUser查询失败", row.Err())
		return user, row.Err()
	}
	errScan := row.Scan(&user.Uid, &user.UserName, &user.Passwd, &user.Avator, &user.CreatAt, &user.Passwd)
	if errScan != nil {
		log.Println("GetUser取值失败", errScan)
		return user, errScan
	}
	return user, err
}
